$.extend(true, PlanningPlaceholder.prototype, objectBase);

// Class for creating placeholders for moving and resizing an element
function PlanningPlaceholder(options) {

    var defaultOptions = {
        position: {
            top: 0,
            left: 0
        },
        draggable: true,
        resizable: false,
        containment: false,
        item: false,
        manager: false
    };

    this.state = $.extend(true, defaultOptions, options);

    if (this.state.containment){
        this.getElement().appendTo($(this.state.containment));
    }
}

// Method for creating HTML element
PlanningPlaceholder.prototype.getElement = function () {
    if (this.element){
        return this.element
    }
    var element;
    var instance = this;

    element = $("<div'/>");

    element.css("position", "absolute");
    element.css("top", this.state.position.top);
    element.css("left", this.state.position.left);

    if (this.state.item){
        var item = this.state.item;
        this.state.item.appendTo(element);
        element.width(item.getWidth());
        element.height(item.getHeight());
    }

    if (this.state.draggable){
        element.draggable({
            containment: this.state.containment,
            drag: function(event, ui){
                instance.state.position = ui.position;
                if(instance.state.manager){
                    instance.state.manager.drag(instance, ui);
                }
            },
            stop: function(event, ui){
                if(instance.state.manager){
                    instance.state.manager.dragStop(instance, ui);
                }
            }
        });
    }

    if (this.state.resizable){
        element.resizable({
            containment: this.state.containment,
            resize: function (event, ui){
                if (instance.state.item){
                    var item = instance.state.item;
                    item.resize(element.width(), element.height());
                }
            }
        });
    }

    element.mousedown(function(){
        if(instance.state.manager){
            instance.state.manager.select(instance);
        }
    });


    this.element = element;

    return element;
}

// Method for rendering instance into HTML element
PlanningPlaceholder.prototype.appendTo = function (element){
    this.state.containment = element;
    $(element).append(this.getElement());

}

PlanningPlaceholder.prototype.delete = function (){
    this.element.remove();
}
